
import config from "@/config"
import http from "@/utils/request"

export default {
    aftersales: {
		list: {
			url: `${config.API_URL}aftersales/index`,
			name: "工单列表",
			get: async function(params){
				let res = await http.get(this.url, params);
				// 开票列表数据格式转换
				if (res.code === 200 && res.data) {
					// msg -> message
					if (res.msg && !res.message) {
						res.message = res.msg;
					}
					// 转换数据格式：将简单的列表格式转换为前端期望的格式
					if (res.data.data && !res.data.list) {
						// 重新构建数据结构
						const listData = {
							total: res.data.total,
							per_page: res.data.per_page,
							current_page: res.data.current_page,
							last_page: res.data.last_page,
							data: res.data.data
						};
						
						res.data = {
							list: listData
						};
					}
				}
				return res;
			}
		},
		secondType: {
			url: `${config.API_URL}aftersales/secondType`,
			name: "工单类型",
			get: async function(params){
				return await http.get(this.url, params);
			}
		},
		detail: {
			url: `${config.API_URL}aftersales/detail`,
			name: "工单详情",
			get: async function(params){
				return await http.get(this.url, params);
			}
		},
		reply: {
			url: `${config.API_URL}aftersales/reply`,
			name: "回复工单",
			post: async function(data){
				return await http.post(this.url, data);
			}
		},
		complete: {
			url: `${config.API_URL}aftersales/complete`,
			name: "关闭工单",
			post: async function(data){
				return await http.post(this.url, data);
			}
		}
    }
}

